package com.ymatou.iapi.userservice.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.auth.parameter.SignAuthBean;
import com.ymatou.iapi.userservice.parameter.enums.AppSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.ChannelSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.TerminalSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.ThirdPartyTypeEnum;
import com.ymatou.iapi.userservice.parameter.enums.UserTypeEnum;
import com.ymatou.iapi.userservice.parameter.enums.VisitLanguageEnum;
import com.ymatou.iapi.userservice.parameter.req.BindThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.req.ThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.UnBindThirdPartyUserReq;
import com.ymatou.iapi.userservice.service.BindThirdPartyUserCall;
import com.ymatou.iapi.userservice.service.CreateUserCall;
import com.ymatou.iapi.userservice.service.UnBindThirdPartyUserCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.ThirdpartyUserbind;
import com.ymttest.database.model.ThirdpartyUserbindHistory;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.model.Userinfoex;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
/**
*锁定用户接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UnBindThirdPartyUser{
	private static UnBindThirdPartyUserReq unBindThirdPartyUserReq;
	private static UnBindThirdPartyUserCall unBindThirdPartyUserCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("绑定第三方用户接口");
	}

	@Before
	public void caseUp() {
		unBindThirdPartyUserReq=new UnBindThirdPartyUserReq();
		unBindThirdPartyUserCall=new UnBindThirdPartyUserCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(unBindThirdPartyUserCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_001() {
		Logger.start(true,"解绑weixin新用户成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("true", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
			verifyDB(uid,unBindThirdPartyUserReq);
//			//TODO 使用java登录验证注册成功
//			Logger.comment("开始登陆,验证用户被锁定");
//			LoginAuthBean lab = new LoginAuthBean();
//			LoginAuthCall lac = new LoginAuthCall();
//			lab.setLoginId(CreateUserBean.getLoginId());
//			lab.setPas(JUserCallService.defaultLoginPwd);
//			lab.setSourceType("app");
//			lab.setClientIp(CreateUserBean.getClientIp());
//			lac.setData(false,lab);
//			lac.callService();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_002() {
		Logger.start(true,"解绑weibo用户成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Weibo);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.Weibo);
			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("true", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_003() {
		Logger.start(true,"解绑绑定Alipay新用户成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("true", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_004() {
		Logger.start(false,"解绑不存在第三方账号,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			unBindThirdPartyUserReq.setThirdPartyId("111");
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("false", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100017", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_005() {
		Logger.start(false,"解绑第三方账号Id和Type不匹配,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.Weibo);
			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("false", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100017", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_006() {
		Logger.start(false,"解绑第三方uid和第三方id不匹配,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid-1);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("false", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100017", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_007() {
		Logger.start(false,"不输入uid,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Weibo);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.Weibo);
			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
//			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("false", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_008() {
		Logger.start(true,"Weibo不输入ThirdPartyId,可以解绑成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Weibo);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.Weibo);
//			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("true", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_009() {
		Logger.start(false,"不输入ThirdPartyType,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Weibo);
			JUserCallService.bindThirdPartyUserCall(bd);
//			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.Weibo);
			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("false", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100031", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_010() {
		Logger.start(true,"WeiXin不输入ThirdPartyId,可以解绑成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
//			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("true", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_011() {
		Logger.start(true,"Alipay不输入ThirdPartyId,可以解绑成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
//			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("true", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_012() {
		Logger.start(true,"解绑qq新用户成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.QQ);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.QQ);
			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("true", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
			verifyDB(uid,unBindThirdPartyUserReq);
//			//TODO 使用java登录验证注册成功
//			Logger.comment("开始登陆,验证用户被锁定");
//			LoginAuthBean lab = new LoginAuthBean();
//			LoginAuthCall lac = new LoginAuthCall();
//			lab.setLoginId(CreateUserBean.getLoginId());
//			lab.setPas(JUserCallService.defaultLoginPwd);
//			lab.setSourceType("app");
//			lab.setClientIp(CreateUserBean.getClientIp());
//			lac.setData(false,lab);
//			lac.callService();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_013() {
		Logger.start(true,"QQ不输入ThirdPartyId,可以解绑成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.QQ);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.QQ);
//			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("true", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_014() {
		Logger.start(true,"解绑weixin新用户成功,删除指定token(wxapp)");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			
			String wxAccessToken=AuthCallServiceV2.createToken(uid, "wxapp");
			String appAccessToken=AuthCallServiceV2.createToken(uid, "app");
			
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("true", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
			verifyDB(uid,unBindThirdPartyUserReq);
			
			SignAuthBean sab=new SignAuthBean();
			sab.setToken(wxAccessToken);
			sab.setTokenSource("wxapp");
			Map<String, Object> m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(false, m.get("success"), "验证Success");
			sab.setToken(appAccessToken);
			sab.setTokenSource("app");
			m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(true, m.get("success"), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	//20181213 追加 globalApp =true GlobalApp 不删除token
	public void Tc_UnBindThirdPartyUser_015() {
		Logger.start(true,"解绑weixin新用户成功,删除指定token(GlobalApp)");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String d1=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			String d2=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			String wxAccessToken=AuthCallServiceV2.createToken(uid, "GlobalApp",d1);
			String appAccessToken=AuthCallServiceV2.createToken(uid, "app",d2);
			
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			bd.setAppSource(AppSourceEnum.GlobalApp);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserReq.setGlobalApp(true);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("true", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
			verifyDB(uid,unBindThirdPartyUserReq);
			
			SignAuthBean sab=new SignAuthBean();
			sab.setToken(wxAccessToken);
			sab.setTokenSource("GlobalApp");
			sab.setDeviceId(d1);
			Map<String, Object> m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(true, m.get("success"), "验证Success");
			sab.setToken(appAccessToken);
			sab.setTokenSource("app");
			m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(true, m.get("success"), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	//20181213 追加 globalApp =true GlobalApp 不删除token
	public void Tc_UnBindThirdPartyUser_016() {
		Logger.start(true,"解绑weixin新用户成功,删除指定token(GlobalWxApp)");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String d1=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			String d2=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			String wxAccessToken=AuthCallServiceV2.createToken(uid, "GlobalWxApp",d1);
			String appAccessToken=AuthCallServiceV2.createToken(uid, "app",d2);
			
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			bd.setAppSource(AppSourceEnum.GlobalApp);
			JUserCallService.bindThirdPartyUserCall(bd);
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			unBindThirdPartyUserReq.setThirdPartyId(bd.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserReq.setGlobalApp(true);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("true", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");
			verifyDB(uid,unBindThirdPartyUserReq);
			
			SignAuthBean sab=new SignAuthBean();
			sab.setToken(wxAccessToken);
			sab.setTokenSource("GlobalWxApp");
			sab.setDeviceId(d1);
			Map<String, Object> m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(true, m.get("success"), "验证Success");
			sab.setToken(appAccessToken);
			sab.setTokenSource("app");
			m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(true, m.get("success"), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UnBindThirdPartyUser_017() {
		Logger.start(true,"解绑weixin用户不影响GlobalWxApp");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String d1=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			String d2=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			String wxAccessToken=AuthCallServiceV2.createToken(uid, "GlobalWxApp",d1);
			String appAccessToken=AuthCallServiceV2.createToken(uid, "app",d2);
			
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			bd.setAppSource(AppSourceEnum.GlobalApp);
			JUserCallService.bindThirdPartyUserCall(bd);
			
			BindThirdPartyUserReq bd2 = JUserCallService.initBindThirdUserReq(uid);
			bd2.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			bd2.setAppSource(AppSourceEnum.App);
			JUserCallService.bindThirdPartyUserCall(bd2);
			
			unBindThirdPartyUserReq.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			unBindThirdPartyUserReq.setThirdPartyId(bd2.getThirdPartyId());
			unBindThirdPartyUserReq.setUserId(uid);
			unBindThirdPartyUserReq.setGlobalApp(false);
			unBindThirdPartyUserCall.setData(unBindThirdPartyUserReq);
			unBindThirdPartyUserCall.callService();
			Logger.verifyEquals("true", unBindThirdPartyUserCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", unBindThirdPartyUserCall.getString("ResponseCode"), "验证ResponseCode");

			//验证2记录
			JUserWapper ju=new JUserWapper();
			
			Logger.comment("验证thirdparty_userbind");
			List<ThirdpartyUserbind> thirdinfo = ju.selectthirdpartyuserbind(uid);
			Logger.verifyEquals(1, thirdinfo.size(), "验证绑定记录删除还剩一条");
			Logger.verifyEquals(AppSourceEnum.GlobalApp.getCode(), thirdinfo.get(0).getAppSource(), "验证GlobalWxApp绑定");
			
			
			SignAuthBean sab=new SignAuthBean();
			sab.setToken(wxAccessToken);
			sab.setTokenSource("GlobalWxApp");
			sab.setDeviceId(d1);
			Map<String, Object> m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(true, m.get("success"), "验证Success");
			sab.setToken(appAccessToken);
			sab.setTokenSource("wxapp");
			m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(false, m.get("success"), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void verifyDB(Integer uid, UnBindThirdPartyUserReq unBindThirdPartyUserReq2) {
		JUserWapper ju=new JUserWapper();
		
		Logger.comment("验证thirdparty_userbind");
		List<ThirdpartyUserbind> thirdinfo = ju.selectthirdpartyuserbind(uid);
		Logger.verifyEquals(0, thirdinfo.size(), "验证绑定记录删除");
		
		Logger.comment("验证thirdparty_userbind_history");
		ThirdpartyUserbindHistory thirdinfohist = ju.selectthirdpartyuserbindhistory(uid).get(0);
		Logger.verifyEquals(false, thirdinfohist.getBinding(), "验证binding状态");
		Logger.verifyEquals(unBindThirdPartyUserReq2.getThirdPartyId(), thirdinfohist.getThirdPartyId(), "验证ThirdPartyId");
		Logger.verifyEquals(unBindThirdPartyUserReq2.getThirdPartyType().getCode(), thirdinfohist.getThirdPartyType(), "验证ThirdPartyType");
	}
}